﻿using System;
using System.Text;

class ReplaceConsecutIdentLettersWithOne
{
    static void Main()
    {
        //Exercise 23.
        //Write a program that reads a string from the console and replaces all series of consecutive identical letters with a 
        //single one. Example: "aaaaabbbbbcdddeeeedssaa" -> "abcdedsa".

        string text = "aaaaabbbbbcdddeeeedssaa";
        StringBuilder shortText = new StringBuilder();
        shortText.Append(text[0]);
        for (int i = 1; i <= text.Length - 1; i++)
        {
            if (text[i - 1] != text[i])
            {
                shortText.Append(text[i]);
            }            
        }

        if (text[text.Length - 1] != text[text.Length - 2])
        {
            shortText.Append(text[text.Length - 1]);
        }
        Console.WriteLine(shortText.ToString());
    }
}

